from django.shortcuts import render


from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from .models import User


class CheckUsernameView(APIView):
    def get(self, request, username):
        # 1,根据用户名查询,用户数量
        count = User.objects.filter(username=username).count()

        # 2,返回响应
        data = {
            "count": count
        }
        return Response(data, status=status.HTTP_200_OK)


class CheckMobileView(APIView):
    def get(self,request,mobile):

        #1,根据手机号查询,用户数量
        count = User.objects.filter(mobile=mobile).count()

        #2,返回响应
        data = {
            "count":count
        }
        return Response(data,status=status.HTTP_200_OK)